import java.awt.geom.Rectangle2D;

import javax.media.opengl.GLAutoDrawable;

import com.jogamp.opengl.util.awt.TextRenderer;


public class TextUtils {

	public static void drawCenteredText(String s, GLAutoDrawable drawable, TextRenderer renderer) {
		int screenWidth = drawable.getWidth();
		int screenHeight = drawable.getWidth();
		renderer.beginRendering(screenHeight, screenWidth);
		// optionally set the color
		renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f);
		Rectangle2D bounds = renderer.getBounds(s);
		int x = (int) (screenWidth / 2 - Math.round(bounds.getWidth()) / 2);
		int y = (int) (screenHeight - screenHeight / 4 - Math.round(bounds.getHeight()) / 2);
		renderer.draw(s, x, y);
		// ... more draw commands, color changes, etc.
		renderer.endRendering();
	}
	
}
